<!--
 * @Author: wangzm
 * @Date: 2020-02-18 10:44:23
 * @LastEditors: wjk
 * @LastEditTime: 2020-08-28 09:48:47
 * @Description: share page
 -->
<template>
  <view></view>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
  onLoad(option) {
    //   extraData = {
    //     toPath: '/pagesOrder/orderCheck/index', 要去的页面
    //     needLogin: true,  // 是否需要登陆
    //   isBack: false,  // 判断是否是返回的用于页面刷新数据
    //     token: '', // token
    //     data: {}  // 传递过去用的数据
    // }
    // 碧选直播小程序跳过来的
    const extraData = this.extraData
    if (extraData) {
      if (extraData.share_code) {
        uni.setStorageSync('share_code', extraData.share_code)
      }
      if (extraData.needLogin && !extraData.token) {
        uni.setStorage({ key: 'pageAfterLogin', data: extraData.toPath })
        this.$navigateTo('/pages/login/index', {}, 'redirectTo')
        return
      } else if (extraData.token) {
        this.SET_TOKEN(extraData.token)
        this.GetUserInfo()
      }
      if (extraData.toPath) {
        if (extraData.toPath.match('/pagesOrder/orderCheck/index')) {
          if (extraData && extraData.data && extraData.data.shopping_list && extraData.data.data) {
            this.$store.dispatch('setGoodsTemp', {
              shopping_list: extraData.data.shopping_list,
              data: extraData.data.data
            })
          }
        }
        this.$navigateTo(extraData.toPath, {}, 'redirectTo')
      } else {
        this.goHome()
      }
    } else {
      this.goHome()
    }
  },
  computed: {
    ...mapGetters(['extraData', 'userToken'])
  },
  methods: {
    goHome() {
      uni.reLaunch({
        url: '/pages/home/index'
      })
    },
    ...mapActions(['SET_TOKEN', 'GetUserInfo'])
  }
}
</script>
